package com.atguigu.gmall.product.rest;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin/product")
public class FileController {

    @Autowired
    private FileService fileService;

    /**
     * POST
     * /admin/product/fileUpload
     */
    @PostMapping("fileUpload")
    public Result fileUpload(@RequestPart MultipartFile file) throws Exception {
        String imgUrl = fileService.fileUpload(file);
        return Result.ok(imgUrl);
    }
}
